﻿using JLPT.Models.FluentConfiguration;
using JLPT.Models.Objects;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Web;

namespace JLPT.Models
{
    public class JLPTContext : DbContext
    {
        //public JLPTContext()
        //    : base("JLPT")
        //{
        //}

        public DbSet<Question> Questions { get; set; }
        public DbSet<QuestionSub> QuestionSubs { get; set; }
        public DbSet<QuestionDetail> QuestionDetails { get; set; }
        public DbSet<QuizHistory> QuizHistories { get; set; }
        public DbSet<Master> Masters { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new QuestionConfiguration());
            modelBuilder.Configurations.Add(new MasterConfiguration());
            modelBuilder.Configurations.Add(new QuestionSubConfiguration());
            modelBuilder.Configurations.Add(new QuestionDetailConfiguation());
           modelBuilder.Configurations.Add(new QuizHistoryConfiguration());

            modelBuilder.Entity<Question >()
                    .HasRequired(m => m.Level )
                    .WithMany(t => t.Questions)
                    .HasForeignKey(m => m.LevelId )
                    .WillCascadeOnDelete(false);
        }
    }
}